<template>
  <a-modal
    :open="open"
    width="1000px"
    :title="rowData?.lsh ? '修改给水卫生' : '新增给水卫生'"
    centered
    :ok-button-props="{ disabled: !isCompleted }"
    ok-text="保存"
    @ok="onOk"
    @cancel="onCancel"
  >
    <a-form class="form-style-flex" name="validate_other" :model="formState" :label-col="{ style: { width: '60px' } }">
      <a-form-item label="受水装备" class="w-1/3" :label-col="{ style: { width: '100px' } }">
        <SelectTable v-model:value="formState.waterReceiveEquipName" type="装备配置" :tableWidth="720" @select="onSelectWater" />
      </a-form-item>
      <a-form-item label="品牌" class="w-1/6">
        <a-input v-model:value="formState.waterReceiveBrand" disabled placeholder="请输入" />
      </a-form-item>
      <a-form-item label="规格" class="w-1/6">
        <a-input v-model:value="formState.waterReceiveSpecs" disabled placeholder="请输入" />
      </a-form-item>
      <a-form-item label="型号" class="w-1/6">
        <a-input v-model:value="formState.waterReceiveModel" disabled placeholder="请输入" />
      </a-form-item>
      <a-form-item label="单位" class="w-1/6">
        <a-input v-model:value="formState.waterReceiveUnit" disabled placeholder="请输入" />
      </a-form-item>

      <a-form-item label="贮水装备" class="w-2/6" :label-col="{ style: { width: '100px' } }">
        <SelectTable v-model:value="formState.waterStorageEquipName" type="装备配置" :tableWidth="720" @select="onSelectStorage" />
      </a-form-item>
      <a-form-item label="品牌" class="w-1/6">
        <a-input v-model:value="formState.waterStorageBrand" disabled placeholder="请输入" />
      </a-form-item>
      <a-form-item label="规格" class="w-1/6">
        <a-input v-model:value="formState.waterStorageSpecs" disabled placeholder="请输入" />
      </a-form-item>
      <a-form-item label="型号" class="w-1/6">
        <a-input v-model:value="formState.waterStorageModel" disabled placeholder="请输入" />
      </a-form-item>
      <a-form-item label="单位" class="w-1/6">
        <a-input v-model:value="formState.waterStorageUnit" disabled placeholder="请输入" />
      </a-form-item>

      <a-form-item label="给水装备" class="w-2/6" v-bind="validateInfos.waterSupplyEquipName" :label-col="{ style: { width: '100px' } }">
        <SelectTable v-model:value="formState.waterSupplyEquipName" type="装备配置" :tableWidth="720" @select="onSelectGive" />
      </a-form-item>
      <a-form-item label="品牌" class="w-1/6">
        <a-input v-model:value="formState.waterSupplyBrand" disabled placeholder="请输入" />
      </a-form-item>
      <a-form-item label="规格" class="w-1/6">
        <a-input v-model:value="formState.waterSupplySpecs" disabled placeholder="请输入" />
      </a-form-item>
      <a-form-item label="型号" class="w-1/6">
        <a-input v-model:value="formState.waterSupplyModel" disabled placeholder="请输入" />
      </a-form-item>
      <a-form-item label="单位" class="w-1/6">
        <a-input v-model:value="formState.waterSupplyUnit" disabled placeholder="请输入" />
      </a-form-item>
      <a-form-item label="卫生条件描述" class="w-full" :label-col="{ style: { width: '100px' } }">
        <a-textarea v-model:value="formState.sanitaryConditionDesc" :row="3" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="水质检查描述" class="w-full" :label-col="{ style: { width: '100px' } }">
        <a-textarea v-model:value="formState.waterQualityDesc" :row="3" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="水质检查结果" class="w-full" :label-col="{ style: { width: '100px' } }">
        <a-textarea v-model:value="formState.waterQualityResult" :row="3" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="备注" class="w-full" :label-col="{ style: { width: '100px' } }">
        <a-textarea v-model:value="formState.memo" :row="3" placeholder="请输入" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script setup>
import { ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import { post } from '@/utils/request'

const emit = defineEmits(['update:open', 'update:value', 'success'])

const props = defineProps({
  open: Boolean,
  rowData: {
    type: Object,
    default: () => ({})
  }
})

const formState = ref({
  waterSupplyEquipName: ''
})
const rulesState = ref({
  waterSupplyEquipName: [{ required: true, message: '请选择给水装备' }]
})
const { isCompleted, resetFields, validateInfos } = useForm(formState, rulesState)

// 受水装备
const onSelectWater = (select) => {
  formState.value.waterReceiveEquipName = select?.equipmentName
  formState.value.waterReceiveEquip = select?.equipmentNumber
  formState.value.waterReceiveBrand = select?.brand
  formState.value.waterReceiveSpecs = select?.gg
  formState.value.waterReceiveModel = select?.model
  formState.value.waterReceiveUnit = select?.dw
}
// 储水装备
const onSelectStorage = (select) => {
  formState.value.waterStorageEquipName = select?.equipmentName
  formState.value.waterStorageEquip = select?.equipmentNumber
  formState.value.waterStorageBrand = select?.brand
  formState.value.waterStorageSpecs = select?.gg
  formState.value.waterStorageModel = select?.model
  formState.value.waterStorageUnit = select?.dw
}
// 给水装备
const onSelectGive = (select) => {
  formState.value.waterSupplyEquipName = select?.equipmentName
  formState.value.waterSupplyEquip = select?.equipmentNumber
  formState.value.waterSupplyBrand = select?.brand
  formState.value.waterSupplySpecs = select?.gg
  formState.value.waterSupplyModel = select?.model
  formState.value.waterSupplyUnit = select?.dw
}

const onOk = async () => {
  const { code, msg } = await post('/war/epidemicOtherPrevention/doSaveEpidemicWater', formState.value)
  if (code !== 0) return message.error(msg)
  message.success(msg)
  emit('update:open', false)
  emit('success')
}

const onCancel = () => {
  emit('update:open', false)
  resetFields()
}

watch(
  () => props.open,
  (val) => {
    if (val) {
      formState.value = { ...props.rowData }
    }
  }
)
</script>
<style lang="less" scoped></style>
